#include "Rasterung.h"


Rasterung::Rasterung(void)
{
}


Rasterung::~Rasterung(void)
{
}

void Rasterung::Rechteck(int x0, int y0, int x1, int y1){
	for(int y = y0; y <= y1; y++) 
		for(int x = x0; x <= x1; x++) 
			Bild::getInstance()->setPixel(x,y);
}

void Rasterung::Dreieck(int x0, int y0, int x1, int y1, int x2, int y2){
	int xmin = std::min(x0, std::min(x1,x2));
	int ymin = std::min(y0, std::min(y1,y2));
	int xmax = std::max(x0, std::max(x1,x2));
	int ymax = std::max(y0, std::max(y1,y2));
	int f0 = (y0-y1)*(xmin-x0) + (x1-x0)*(ymin-y0);
	int f1 = (y1-y2)*(xmin-x1) + (x2-x1)*(ymin-y1);
	int f2 = (y2-y0)*(xmin-x2) + (x0-x2)*(ymin-y2); 
	for(int y = ymin; y<=ymax; y++) 
	{ 
		int ff0 = f0, ff1 = f1, ff2 = f2; 
		for(int x = xmin; x<=xmax; x++) 
		{ 
			if(ff0 >= 0 && ff1 >=0 && ff2 >= 0) 
				Bild::getInstance()->setPixel(x,y); 
			ff0 = ff0 + (y0-y1); 
			ff1 = ff1 + (y1-y2); 
			ff2 = ff2 + (y2-y0); 
		} 
		f0 = f0 + (x1-x0); 
		f1 = f1 + (x2-x1); 
		f2 = f2 + (x0-x2); 
	}
}
